using System.ComponentModel;

namespace WB.Mvc.Forms
{
	public class EnumToRadioButtonListFieldStrategy: IModelFieldStrategy
	{
		/// <summary>
		/// Creates a <see cref="Field"/>.
		/// </summary>
		public Field Create(string name)
		{
			return null;
		}

		/// <summary>
		/// Creates a field based on <see cref="PropertyDescriptor" />.
		/// </summary>
		/// <remarks>
		/// It is intended, though not required, that users of this strategy accept
		/// <c>null</c> return values as meaning that this field strategy
		/// does not wish to handle this <see cref="PropertyDescriptor"/>.
		/// </remarks>
		public Field Create(PropertyDescriptor descriptor)
		{
			if (!descriptor.PropertyType.IsEnum)
				return null;
			if (descriptor.IsReadOnly)
				return null;

			return new EnumField(descriptor.Name, descriptor.PropertyType);
		}
	}
}